<template>
  <div class="tool">
    <!-- 顶部头像区域 -->
    <div class="tool-avatar">
      <div class="tool-avatar-img">
        <img :src="userInfo.avatar" alt="" />
      </div>
    </div>
    <!-- 消息列表/通讯录切换 -->
    <el-tooltip placement="left" effect="dark" content="消息列表">
      <div class="nav-icon">
        <span class="iconfont icon-wechat" :class="{
          'tool-active': activeTabName === 'message',
        }" @click="setActiveTabName('message')"></span>
      </div>
    </el-tooltip>
    <el-tooltip placement="left" effect="dark" content="通讯录">
      <div class="nav-icon">
        <span :class="{
          'tool-active': activeTabName === 'contacts',
        }" class="iconfont icon-friends-o" @click="setActiveTabName('contacts')"></span>
      </div>
    </el-tooltip>
  </div>
</template>
<script>
import { defineComponent, ref, computed } from "vue";
import { emitter } from "../../../utils/emitter";
import { useUserStore } from "../../../store/user";
export default defineComponent({
  name: "chat-nav",
  components: {},
  emits: ["setActiveTab"],
  setup(props, ctx) {
    const userStore = useUserStore();
    const userInfo = computed(() => userStore.userInfo);
    const activeTabName = ref("message");
    const setActiveTabName = (active) => {
      activeTabName.value = active;
      ctx.emit("setActiveTab", active);
    };
    emitter.on("changeNav", (data) => {
      setActiveTabName(data);
    });
    return { userInfo, activeTabName, setActiveTabName };
  },
});
</script>
<style lang="less" scoped>
.tool {
  padding: 10px 5px 10px;
  height: 98%;
  position: relative;

  .tool-avatar {
    margin: 10px 0;
    .tool-avatar-img {
      margin: 0 auto;
      width: 55px;
      height: 55px;
      border-radius: 50%;
      overflow: hidden;
      cursor: pointer;
      img {
        width: 100%;
        height: 100%;
        object-fit: cover;
        transition: all 2s;
        &:hover {
          transform: rotate(360deg);
        }
      }
    }
  }
  .nav-icon {
    text-align: center;
    padding: 16px 0;
    span {
      font-size: 30px;
      cursor: pointer;
    }
    .tool-active {
      color: #09b955;
    }
  }
}
</style>